package cj.web.admin.dao;

import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.MessageInfo;

@DAO
public interface MessageInfoDAO {

	@SQL("SELECT * FROM MessageInfo WHERE deleteFlag=1 #if(:t.name!=null){AND (name like '%##(:t.name)%' or tel like '%##(:t.tel)%') } #if(:t.type!='-1'){AND type =:t.type } #if(:t.state!='-1'){AND state =:t.state } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    List<MessageInfo> query(@SQLParam("t") MessageInfo messageInfo);
	
	@SQL("SELECT count(*) FROM MessageInfo WHERE deleteFlag=1 #if(:t.name!=null){AND (name like '%##(:t.name)%' or tel like '%##(:t.tel)%') } #if(:t.type!='-1'){AND type =:t.type } #if(:t.state!='-1'){AND state =:t.state } ")
    int querysize(@SQLParam("t") MessageInfo messageInfo);
    
    @SQL("SELECT * FROM MessageInfo WHERE id=:1")
    MessageInfo queryById(int id);
    
    @SQL("INSERT INTO MessageInfo (code,name,tel,address,type,descs,photo,video,state,memo,openId,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.code,:t.name,:t.tel,:t.address,:t.type,:t.descs,:t.photo,:t.video,:t.state,:t.memo,:t.openId,1,:t.createUser,now(),:t.updateUser,now())")
    void create(@SQLParam("t") MessageInfo messageInfo);
	
	@SQL("UPDATE MessageInfo SET state=:t.state,memo=:t.memo,updateUser=:t.updateUser,updateAt=now() WHERE id=:t.id")
    void update(@SQLParam("t") MessageInfo messageInfo);
    
    @SQL("UPDATE MessageInfo SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("UPDATE MessageInfo SET state=:2,updateUser=:3,updateAt=now() WHERE id=:1")
    void updateById(int id,int state,String updateUser);
}